#include "log.h"

const char *logname = "osc_output.log";

#ifndef _DEBUG
FILE *logfile;
#endif

void LOG_INIT() {
#ifndef _DEBUG
    logfile = fopen(logname, "w");
    assert(logfile != NULL);
#endif
}

void LOG_EXIT() {
#ifndef _DEBUG
    fclose(logfile);
#endif
}

void LOG_INFO(const char *format, ...) {
    #ifdef _DEBUG
    fprintf(logfile, "\033[34m%s\033[0m", "INFO: ");
    #else
    fprintf(logfile, "%s", "INFO: ");
    #endif
    va_list list;
    va_start(list, format);
    vfprintf(logfile, format, list);
    va_end(list);
}

void LOG_ERR(const char *format, ...) {
    #ifdef _DEBUG
    fprintf(logfile, "\033[31m%s\033[0m", "ERROR: ");
    #else
    fprintf(logfile, "%s", "ERROR: ");
    #endif
    va_list list;
    va_start(list, format);
    vfprintf(logfile, format, list);
    va_end(list);
}